﻿using System;
using System.Data;

namespace visinia.SmartEngine.Providers
{
    /// <summary>
    /// The visinia.SmartEngine interface which every visinia data store
    /// provider must implement
    /// </summary>
    public abstract partial class SmartEngineDataProvider
    {
        #region INIT
        private static SmartEngineDataProvider _provider;
        private static object _lock = new object();

        public static SmartEngineDataProvider Provider
        {
            get { InternalInitialize(); return _provider; }
        }

        /// <summary>
        /// Load data provider dynamically if already not in memory
        /// </summary>
        private static void InternalInitialize()
        {
            if (_provider == null)
            {
                lock (_lock)
                {
                    if (_provider == null)
                    {                        
                        _provider = (SmartEngineDataProvider)ProviderController.CreateDataProvider("visinia.SmartEngine");
                        if (_provider == null)
                            throw new Exception("Unable to load SmartEngineDataProvider");
                    }
                }
            }
        }
        #endregion

        #region MODULES
        public abstract IDataReader AddModule(int ModuleInstalledId, string Title, string TitleImageUrl, string TitleImageNavigationUrl, string CssClass, int Width, int Height, int PageId, string Pane, int PaneOrder, bool Visible);
        public abstract void DeleteModule(int ModuleId);
        public abstract void UpdateModule(int ModuleId, int ModuleInstalledId, string Title, string TitleImageUrl, string TitleImageNavigationUrl, string CssClass, int Width, int Height, int PageId, string Pane, int PaneOrder, bool Visible);
        public abstract IDataReader GetModule(int ModuleId);
        public abstract IDataReader GetModules(int PageId);        
        #endregion

        #region ModulePrivateSettings
        public abstract IDataReader GetModulePrivateSettings(int ModuleId);
        public abstract void AddModulePrivateSetting(int ModuleId, string Key, string Value);
        public abstract void UpdateModulePrivateSetting(int ModuleId, string Key, string Value);
        public abstract void DeleteModulePrivateSettings(int ModuleId);
        public abstract void DeleteModulePrivateSetting(int ModuleId, string Key);
        #endregion

        #region PAGE
        public abstract IDataReader AddPage(string Name, string Title, int PluginId);
        public abstract void DeletePage(int PageId);
        public abstract void UpdatePage(int PageId, string Name, string Title, int PluginId);
        public abstract IDataReader GetPages();
        #endregion

        #region REPOSITORY
        public abstract IDataReader GetInstalledModules();
        public abstract IDataReader RegisterModule(string Name, string Package, string ModuleUrl, string ModuleSettingsUrl, string Icon, string Image, string Help);
        public abstract void UnRegisterModule(int ModuleInstalledId);
        
        #endregion

        #region SITE SETTINGS
        public abstract IDataReader GetSiteSettings();
        public abstract void AddSiteSetting(string key, string value);
        public abstract void UpdateSiteSetting(string key, string value);
        public abstract void DeleteSiteSetting(string key);
        #endregion

        #region INSTALLER
        public abstract bool ExecuteScript(string script);        
        #endregion

        #region PLUGINS
        public abstract IDataReader GetInstalledPlugins();
        public abstract IDataReader AddPlugin(string Name, string Description, string UrlSeparator, string UrlRewriteController, string SitemapController, string Version);
        public abstract IDataReader UpdatePlugin(int PluginId, string Name, string Description, string UrlSeparator, string UrlRewriteController, string SitemapController, string Version);
        public abstract void DeletePlugin(int PluginId);
        #endregion 
       
        #region LOG
        public abstract void AddLog(string user, DateTime dateTime, string message);
        public abstract IDataReader GetLog();
        #endregion    
    }
}
